package com.care.controller.admin.sys;

import com.care.author.AuthRequired;
import com.care.controller.vo.JsonResult;
import com.care.dao.mapper.SysLogMapper;
import com.care.dao.model.SysLog;
import com.care.utils.page.PageView;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 后台管理员api：日志管理
 * @author xujinnan
 *
 */
@RequestMapping("/admin/log")
@RestController
public class AdminSysLogApi {

    @Autowired
    private SysLogMapper sysLogMapper;

    /**
     * 日志列表
     * @param request
     * @return
     */
    @RequestMapping("list")
    @AuthRequired
    public JsonResult logList(HttpServletRequest request, PageView<SysLog> pageView, Integer logType) {
        Example example = new Example(SysLog.class);
        Criteria criteria = example.createCriteria();
        if(logType != null){
            criteria.andEqualTo("logType", logType);
        }
        example.orderBy("logTime").desc();
        List<SysLog> list = sysLogMapper.selectByExampleAndRowBounds(example, new RowBounds(pageView.getFirstResult(), pageView.getMaxresult()));
        pageView.setRecords(list);
        pageView.setTotalrecord(sysLogMapper.selectCountByExample(example));//总记录数
        return JsonResult.success(pageView);
    }

}
